import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    info: localStorage.getItem('info') ? JSON.parse(localStorage.getItem('info')) : []
  },
  getters: {
  },
  mutations: {
    saveData ( state, paylady ) {
      let index = state.info.findIndex(item => item.id == paylady.id)
      if ( index == -1 ) {
        state.info.push( paylady );
      } else {
        state.info[ index ].num++;
      }
      localStorage.setItem( 'info', JSON.stringify( state.info ) );
    }
  },
  actions: {
  },
  modules: {
  }
})
